package com.kingmgg.baseapp.vm

import android.app.Application
import android.os.Build
import android.text.TextUtils
import android.util.Log
import android.widget.Toast
import androidx.databinding.ObservableLong
import androidx.lifecycle.viewModelScope
import com.alibaba.android.arouter.launcher.ARouter
import com.google.gson.Gson
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import com.kingmgg.baseapp.BuildConfig
import com.kingmgg.baseapp.path.SecondPath
import com.kingmgg.kg_base.ui.BaseViewModel
import com.kingmgg.lib_common.model.Banner
import com.kingmgg.lib_framework.glide.GlideEngine
import com.kingmgg.net_work.callback.RxConsumer
import com.kingmgg.net_work.manager.ApiManager
import com.kingmgg.net_work.response.BaseResponse
import com.luck.picture.lib.basic.PictureSelector
import com.luck.picture.lib.config.SelectMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.interfaces.OnResultCallbackListener
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Observer
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.launch
import java.util.ArrayList
import java.util.concurrent.Flow.Subscriber

/**
 *    Create by 金KingMgg  kingmgg
 *    on 2023/11/20 10:06
 *    程序人员写程序，又拿程序换酒钱
 *
 */
class MainViewModel(application: Application) : BaseViewModel(application) {
    var textString = ObservableLong(1L)


    fun buttonClick() {
//        ARouter.getInstance().build(SecondPath).navigation()
        Toast.makeText(getApplication(), "哈哈哈$mActivity", Toast.LENGTH_LONG).show()
        textString.set(textString.get() + 1)

        viewModelScope.launch {
            ApiManager.api.getHomeBanner()
        }


    }

    fun buttonClick1() {

        XXPermissions.with(mActivity)
            .permission(Permission.MANAGE_EXTERNAL_STORAGE)
            .request(object : OnPermissionCallback {
                override fun onGranted(permissions: MutableList<String>, allGranted: Boolean) {
                    Toast.makeText(mActivity, "权限通过", Toast.LENGTH_LONG).show()
                }

                override fun onDenied(permissions: MutableList<String>, doNotAskAgain: Boolean) {
                    super.onDenied(permissions, doNotAskAgain)
                    XXPermissions.startPermissionActivity(mActivity)
                }
            })

    }

    fun buttonClick2() {


        PictureSelector.create(mActivity)
            .openGallery(SelectMimeType.TYPE_ALL)
            .setImageEngine(GlideEngine.createGlideEngine())
            .forResult(object : OnResultCallbackListener<LocalMedia> {
                override fun onResult(result: ArrayList<LocalMedia>?) {
                    println("PictureSelector--> ${result!![0].path}")
                }

                override fun onCancel() {

                }
            })


    }


}